<template>
  <div class="panel">
    <el-dialog title="编辑权限" :visible.sync="panelShow" :before-close="cancel">
      <el-form :model="form" label-width="80px">
        <el-form-item label="权限名称">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="权限标识">
          <el-input v-model="form.code"></el-input>
        </el-form-item>
        <el-form-item label="权限描述">
          <el-input v-model="form.description"></el-input>
        </el-form-item>
        <el-form-item label="企业可见">
          <!-- <el-input v-model="form.enVisible"></el-input> -->
          <span>不可见</span>
          <el-switch
            v-model="form.enVisible"
            active-color="#13ce66"
            inactive-color="#ff4949"
            active-value="1"
            inactive-value="0"
          >
          </el-switch>
          <span>可见</span>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="submit">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getPerApi, updatePerApi, addPerApi } from '@/api/permission'
export default {
  // 控制面板显示隐藏
  props: ['panelShow'],
  data() {
    return {
      form: {
        name: '',
        code: '',
        description: '',
        enVisible: ''
      }
    }
  },
  methods: {
    // 用来接收新增权限的数据
    getData(type, pid) {
      this.form.type = type
      this.form.pid = pid
    },
    // 提交修改数据&新增
    async submit() {
      if (this.form.id) {
        // 编辑
        await updatePerApi(this.form)
      } else {
        addPerApi(this.form)
      }
      this.$message.success('修改成功')
      this.cancel()
      this.$emit('updateData')
    },
    // 点击取消关闭
    cancel() {
      this.$emit('update:panelShow', false),
        (this.form = {
          name: '',
          code: '',
          description: '',
          enVisible: ''
        })
    },
    async getPerObj(id) {
      const res = await getPerApi(id)
      this.form = res.data.data
    }
  }
}
</script>

<style></style>
